package com.cookbook.cookbookservice.common.util;

/**
 * @program: mid-tourism-service
 * @ClassName GeoTransferUtil
 * @description:
 * @author: MiaoChao
 * @create: 2024-07-08 16:31
 * @Version 1.0
 **/
public class GeoTransferUtil {

    /**
     * GCJ02坐标转BD09坐标
     * @param lng 经度
     * @param lat 纬度
     * @return BD09坐标
     */
    public static double[] gcj02ToBd09(double lng, double lat) {
        double[] bd = new double[2];
        double z = Math.sqrt(lng * lng + lat * lat) + 0.00002 * Math.sin(lat * xPi());
        double theta = Math.atan2(lat, lng) + 0.000003 * Math.cos(lng * xPi());
        bd[0] = z * Math.cos(theta) + 0.0065;
        bd[1] = z * Math.sin(theta) + 0.006;
        return bd;
    }

    private static double xPi() {
        return 3.14159265358979324 * 3000.0 / 180.0;
    }

    public static void main(String[] args) {
        double[] bd = gcj02ToBd09(116.397029, 39.917839);
        System.out.println(bd[0] + "," + bd[1]);
    }

}